package com.epadmin.app.login;

import com.ep.general.ActionSupportCustom;
import com.ep.general.admin.Administrator;
import com.ep.general.admin.AdministratorMdt;
import com.ep.general.app.Utils;
import com.ep.general.app.login.AbstractLoginAction;

public class LoginAction extends AbstractLoginAction<Administrator> implements LoginRequierd {

	private static final long serialVersionUID = -4646444766666308188L;

	@Override
	public String execute() throws Exception {
		String login = getLogin();
		String password = getPassword();
		if (login == null || password == null) {
			return LOGIN;
		}

		Administrator admin = new AdministratorMdt().get(login, Utils.convertToMd5(password));

		if (admin != null) {
			setLoggedUser(admin);

			return ActionSupportCustom.START_PAGE;

		} else {
			addActionError("Niepoprawny login lub hasło");
			return LOGIN;
		}
	}

}
